package com.apes.oap.request.converter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

/**
 * 功能：
 *
 * @author xul
 * @create 2018-09-05 13:44
 */
@SuppressWarnings("unchecked")
public class RopRequestWrapper extends HttpServletRequestWrapper {

    private Map<String, String[]> params = null;

    public RopRequestWrapper(HttpServletRequest request, Map inParam) {
        super(request);
        params = new HashMap(inParam);
    }

    public void setParameter(String key, String value) {
        params.put(key, new String[]{value});
    }

    public void setParameter(String key, String[] values) {
        params.put(key, values);
    }

    @Override
    public String getParameter(String name) {
        String[] values = params.get(name);
        if (values == null) return null;
        return values.length == 0 ? null : values[0];
    }

    @Override
    public Map<String, String[]> getParameterMap() {
        return params;
    }

    @Override
    public Enumeration<String> getParameterNames() {
        Vector l = new Vector(params.keySet());
        return l.elements();
    }

    @Override
    public String[] getParameterValues(String name) {
        return params.get(name);
    }

}